<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCouponPackageOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupon_package_orders', function (Blueprint $table) {
            $table->unsignedBigInteger('orderId');
            $table->unsignedInteger('brandId')->default(0);
            $table->unsignedInteger('shopId')->default(0);
            $table->unsignedInteger('userId')->default(0);
            $table->unsignedInteger('couponPackageId')->default(0)->comment('券包id');
            $table->unsignedTinyInteger('sourceType')->default(0)->comment('1pos 2小程序');
            $table->unsignedInteger('payPrice')->default(0)->comment('支付金额');
            $table->unsignedInteger('shopIncomes')->default(0)->comment('门店分账');
            $table->unsignedTinyInteger('payStatus')->default(0)->comment("0待支付 1已支付");

            // 统一表字段
            $table->integer('createdAt')->default(0)->comment('创建时间');
            $table->integer('createdByUid')->default(0)->comment('创建人');
            $table->integer('updatedAt')->default(0)->comment('修改时间');
            $table->integer('updatedByUid')->default(0)->comment('修改人');

            // 索引
            $table->primary('orderId', 'idx_orderId');        // 主键非自增
            $table->index('userId', 'idx_userId');
            $table->index('couponPackageId', 'idx_couponPackageId');
            $table->index('createdAt', 'idx_createdAt');
            $table->index('shopId', 'idx_shopId');


            $table->collation = 'utf8mb4_general_ci';
            $table->comment   = '券包购买记录';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupon_package_orders');
    }
}
